package ua.maxicash.util;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;

public class WorkRestrictions {
	
	public static Criterion getRestrictionForFilter(Filter filter){
		
		Criterion criterion = null;
		
		if (filter.getField().equals("city")) {
			criterion = Restrictions.or(Restrictions.like("city.ruName","%"+filter.getData()+"%")
					,Restrictions.like("city.enName","%"+filter.getData()+"%"));
		}
		
		if (filter.getField().equals("jobType")) {
			
			criterion = Restrictions.like("jobTypeAlias.title","%"+filter.getData()+"%");
			//criterion = Property.forName("jobType.title").like("%"+filter.getData()+"%");
		}
		
		if (filter.getField().equals("region")) {
			criterion = Restrictions.or(Restrictions.like("city.region.ruName","%"+filter.getData()+"%")
					,Restrictions.like("city.region.enName","%"+filter.getData()+"%"));
		}
		
		if (filter.getField().equals("country")) {
			criterion = Restrictions.or(Restrictions.like("city.country.ruName","%"+filter.getData()+"%")
					,Restrictions.like("city.country.enName","%"+filter.getData()+"%"));
		}
		
//		if (filter.getField().equals("workDate")) {
//			criterion = Restrictions.or(Restrictions.like("","%"+filter.getData()+"%")
//					,Restrictions.like("city.country.enName","%"+filter.getData()+"%"));
//		}
		
		if (filter.getField().equals("wage")) {
			criterion = Restrictions.ge("wage",Double.parseDouble(filter.getData()));
		}
		
		if (filter.getField().equals("employer")) {
			criterion = Restrictions.like("employer.email","%"+filter.getData()+"%");
		}
		
		return criterion;
		
	}
	
}
